/**
 * 剑指 Offer 65. 不用加减乘除做加法
 * https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/
 */

/**
 * @param {number} a
 * @param {number} b
 * @return {number}
 */
function add(a, b) {
  let n1 = a;
  let n2 = b;
  while (n2) {
    const temp = n1;
    n1 ^= n2;
    n2 = (temp & n2) << 1;
  }
  return n1;
}

console.log(add(1, 2) === 3);
console.log(add(-1, 2) === 1);
console.log(add(-1, -2) === -3);
